# encoding=utf-8
from LBT.BaseParent.BaseLbt import lbtlogin
from LBT.GeneralOperation.SmsOperation import smsoperation
from LBT.Resource.SmsAtt import SmsAtt


class sendmessage(lbtlogin, SmsAtt):
    '''发短信模块测试+我发送的模块测试
    包括发给老师和学生，包括定时和非定时
    '''

    @lbtlogin.loginFun
    def test_studentSendNow(self):
        '''给学生发及时短信
        20190330duvee
        '''
        self.docstr ='给学生发及时短信'
        # 初始化短信操作业务模块
        smsoper = smsoperation(self.driver)
        # 调用向学生发送及时短信，返回学生姓名和短信内容
        returnInfo = smsoper.studentSendSms(self, False)
        # 发短信按钮
        self.driver.find_element_by_id(self.sms_btn_submit).click()
        # 校验是否发送成功，进入我发送的模块
        self.assertEqual(smsoper.checkSmsIsSuccess(returnInfo[0], returnInfo[1]), True)


    @lbtlogin.loginFun
    def test_studentSendTiming(self):
        '''给学生发定时短信'''
        self.docstr = '给学生发定时短信'
        #初始化短信操作业务模块
        smsoper = smsoperation(self.driver)
        #调用向学生发送定时短信，返回学生姓名和短信内容
        returnInfo=smsoper.studentSendSms(self,True)
        # 发短信按钮
        self.driver.find_element_by_id(self.sms_btn_submit).click()
        # 校验是否发送成功，进入我发送的模块
        self.assertEqual(smsoper.checkSmsIsSuccess(returnInfo[0], returnInfo[1]), True)

    @lbtlogin.catchfun
    def test_teacherSendNow(self):
        '''给老师发及时短信'''
        self.docstr = '给老师发及时短信'
        # 进入短信发送模块
        smsoper = smsoperation(self.driver)
        self.login()
        dr = self.driver
        # 进入模块
        isin = self.moduleOp.openMoudleAndIn(self.smsNavigation_class, self.smsModule_url)
        self.assertTrue(isin)
        dr.find_element_by_xpath(self.sms_switchto_teacher_xpath).click()
        # 选择老师
        teachername = smsoper.chioceUser(self.sms_switch_tea_id)
        testT = dr.find_element_by_id(self.sms_select_userArea).text
        self.assertIn(teachername, testT)
        # 填写短信内容
        smsInfo = smsoper.smsTemplate(dr)
        smsInfo = smsoper.writeContent('向' + teachername + '老师发及时短信，时间为：', smsInfo)
        # 发短信按钮
        self.driver.find_element_by_id(self.sms_btn_submit).click()
        # 校验是否发送成功，进入我发送的模块
        self.assertEqual(smsoper.checkSmsIsSuccess(smsInfo, teachername), True)

    @lbtlogin.catchfun
    def test_teacherSendTiming(self):
        '''给老师发定时短信'''
        self.docstr = '给老师发定时短信'
        # 进入短信发送模块
        smsoper = smsoperation(self.driver)
        self.login()
        dr = self.driver
        # 进入模块
        isin = self.moduleOp.openMoudleAndIn(self.smsNavigation_class, self.smsModule_url)
        self.assertTrue(isin)
        dr.find_element_by_xpath(self.sms_switchto_teacher_xpath).click()
        # 选择老师
        teachername = smsoper.chioceUser(self.sms_switch_tea_id)
        testT = dr.find_element_by_id(self.sms_select_userArea).text
        self.assertIn(teachername, testT)
        # 填写短信内容
        smsInfo = smsoper.smsTemplate(dr)
        print(smsInfo)
        smsInfo = smsoper.writeContent('向' + teachername + '老师发定时短信，时间为：', smsInfo)
        print(smsInfo)
        self.driver.find_elements_by_name(SmsAtt.sms_timing_name)[1].click()
        dr.find_element_by_id(self.sms_timing_id).send_keys(self.getTimintInfo())
        dr.find_element_by_class_name(self.sms_timing_btn).click()
        # 发短信按钮
        self.driver.find_element_by_id(self.sms_btn_submit).click()
        # 校验是否发送成功，进入我发送的模块
        self.assertEqual(smsoper.checkSmsIsSuccess(smsInfo, teachername), True)

    @lbtlogin.catchfun
    def aatest_teacherSendTo(self):
        '''
        一个老师给另一个老师发短信----------废弃不用
        张志莹--20190330
        :return:
        '''
        self.docstr = '给老师发定时短信'
        # 进入短信发送模块
        smsoper = smsoperation(self.driver)
        self.login()
        dr = self.driver
        # 进入模块
        isin = self.moduleOp.openMoudleAndIn(self.smsNavigation_class, self.smsModule_url)
        self.assertTrue(isin)
        dr.find_element_by_xpath(self.sms_switchto_teacher_xpath).click()
        # 选择老师
        teachername = '演示专用帐号'
        smsoper.chioceteacherone('cbDept7021', teachername)
        testT = dr.find_element_by_id(self.sms_select_userArea).text
        self.assertIn(teachername, testT)
        # 填写短信内容
        smsInfo = smsoper.writeContent('向' + teachername + '老师发及时短信，时间为：')
        # 发短信按钮
        self.driver.find_element_by_id(self.sms_btn_submit).click()
        # 校验是否发送成功，进入我发送的模块
        self.assertEqual(smsoper.checkSmsIsSuccess(smsInfo, teachername), True)
